import { ajax, decode } from '@jecloud/utils';
const API_RBAC_LOGIN_THIRD_TEMPCODE = '/je/rbac/cloud/login/thirdTempCode';
/**
 * 三方登录根据临时码获得登录信息
 * @param {String} tempCode 临时码，一分钟失效
 * @returns
 */
export function loadThirdTempCodeApi(tempCode) {
  return ajax({ url: API_RBAC_LOGIN_THIRD_TEMPCODE, token: false, params: { tempCode } }).then(
    (data) => {
      if (data.success) {
        const config = decode(data.data);
        if (config.url) {
          config.url = config.url.split('#')[1] || config.url;
        }
        config.depts = config.info;
        return config;
      } else {
        return Promise.reject(data);
      }
    },
  );
}
